<template>
	<view class="container">
		<view class="card">
			<view class="item"><view>会议主题：{{ form.topic }}</view></view>
			<view class="item"><view>演&nbsp;讲&nbsp;人&nbsp;：{{ form.host_man }}</view></view>
			<view class="item"><view>负&nbsp;责&nbsp;人&nbsp;：{{ form.respons_man }}</view></view>
			<view class="item"><view>开始时间：{{ form.starttime }}</view></view>
			<view class="item"><view>结束时间：{{ form.overtime }}</view></view>
		</view>
		<view class="card" style="margin-bottom: 60upx;">
			<view class="title flex-row">
				<view class="name">开始会议现场照片</view>
			</view>
			<view class="item" style="padding-top: 20upx;">
				<upload v-if="isLoaded" @upload="uploadPics" @delete="delPic" :showBtn="showBtn" :files="pics" :icon="icon" :count="3"></upload>
			</view>
		</view>
		<view @click="start" v-if="joc == 1 && form.status == 1" class="btn">开始会议</view>
		<view @click="cancel" v-if="joc == 1 && form.status == 1" class="btn error">取消会议</view>
		<view @click="edit" v-if="joc == 1 && form.status == 2" class="btn">编辑会议</view>
		<view @click="detail" v-if="form.status > 1" class="btn">会议记录详情</view>
		<view @click="sign" v-if="joc == 1 && form.status == 2" class="btn error">签到、签退二维码</view>
		<view @click="goBack" class="btn error">返回上一级</view>
	</view>
</template>

<script>
import upload from '@/components/upload/index.vue';
export default{
	components: { upload },
	data(){
		return {
			userid: uni.getStorageSync('userid'),
			isLoaded: false,
			icon: true,
			showBtn: true,
			meet_id: '',
			joc: 0,
			pics: [],
			form: {}
		}
	},
	onLoad(option){
		this.meet_id = option.id;
		this.joc = option.joc;
	},
	onShow(){
		this.getDetail();
	},
	methods: {
		// 返回
		goBack(){
			uni.navigateBack();
		},
		// 获取详情
		getDetail(){
			let _this = this;
			uni.request({
				url: this.$API.eduSafeMeetingDetail,
				data: { 
					userid: this.userid, 
					meet_id: this.meet_id
				},
				header: this.$API.get_head(),
				success: (res)=>{
					_this.form = res.data.data;
					_this.isLoaded = true;
					
					if(_this.form.start_pics){
						let pics = _this.form.start_pics.split(',');
						_this.pics = pics.map(item=>this.$API.baseURL + item);
						_this.icon = false;
						_this.showBtn = false;
					}
				}
			})
		},
		// 删除照片
		delPic(obj){
			this.pics = this.pics.filter((item, idx)=>index != idx);
		},
		// 上传照片
		uploadPics(obj){
			let _this = this;
			obj.temps.forEach(function(item,index){
				uni.showLoading({title: '上传中'});
				uni.uploadFile({
					url: _this.$API.upload,
					name: 'file',
					filePath: item,
					success: function(res) {
						uni.hideLoading();
						res.data = JSON.parse(res.data);
						_this.pics.push(res.data.fileName);
					},fail(){
						uni.hideLoading();
						uni.showToast({
							icon: 'none',
							title: '上传失败'
						})
					}
				});
			})
		},
		// 取消
		cancel(){
			let _this = this
			uni.showModal({
				title: '提示',
				content: '是否确认取消会议?',
				success: (res)=>{
					if(res.confirm){
						uni.request({
							url: _this.$API.eduSafeMeetingCancel,
							data: { 
								userid: _this.userid, 
								meeting_id: _this.meet_id
							},
							header: _this.$API.get_head(),
							success: (res)=>{
								uni.showToast({
									icon: 'none',
									title: '会议取消成功'
								})
								uni.navigateBack()
							}
						})
					}
				}
			})
		},
		// 编辑
		edit(){
			uni.navigateTo({
				url: 'edit?id='+this.meet_id
			})
		},
		// 详情
		detail(){
			uni.navigateTo({
				url: 'editRecord?id='+this.meet_id
			})
		},
		// 签到
		sign(){
			uni.navigateTo({
				url: 'sign?title='+this.form.topic+'&id='+this.meet_id
			})
		},
		// 开始会议
		start(){
			let _this = this;
			
			// 判断是否上传现场图片
			if(this.pics.length == 0){
				return uni.showToast({
					icon: 'none',
					title: '请上传会议现场参会人员照片'
				})
			}
			
			// 确认
			uni.showModal({
				title: '是否开始会议？',
				content: '开始会议前请确认参与人员已经签到',
				cancelText: '查看签到',
				cancelColor: '#999999',
				confirmText: '确认开始',
				confirmColor: '#1692DC',
				success: (res)=>{
					if(res.cancel) _this.sign();
					if(res.confirm){
						uni.request({
							url: this.$API.eduSafeMeetingStart,
							data: { 
								userid: this.userid, 
								meet_id: this.meet_id,
								pics: this.pics.join(',')
							},
							method: 'POST',
							header: this.$API.get_head(),
							success: (res)=>{
								_this.getDetail();
							}
						})
					}
				}
			})
		}
	}
}
</script>

<style scoped>
.container{
	height: 100vh;
	overflow: hidden;
}

/*列表*/
.card{
	background: #fff;
	overflow: hidden;
	margin: 20upx 20upx 0;
	border-radius: 16upx;
	padding: 14upx 20upx 8upx;
	border: 2upx solid #F6F6F6;
	box-shadow: 0 0 4upx #eee;
}
.card:first-child{
	margin: 20upx 0 0;
	border-radius: 0;
}
.card:first-child .item{
	text-indent: 10upx;
}
.card .title{
	margin-bottom: 6upx;
}
.card .title view{
	height: 42upx;
	font-size: 28upx;
}
.card .title view.name{
	text-indent: 20upx;
	position: relative;
}
.card .title view.name::before{
	content: '';
	width: 10upx;
	height: 26upx;
	background: #5F96F2;
	border-radius: 4upx;
	position: absolute;
	top: 14upx;
	left: 0;
}
.btn{
	color: #fff;
	width: 280upx;
	height: 52upx;
	font-size: 26upx;
	line-height: 52upx;
	border-radius: 6upx;
	text-align: center;
	margin: 0 auto 40upx;
	background-color: #1692DC;
}
.btn.error{
	background-color: red;
}
</style>
